package com.appwoo.txtws.component;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import com.appwoo.txtws.thread.ImageDownloadTask;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ImageHelper
{
  private static int computeInitialSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
  {
    double d1 = paramOptions.outWidth;
    double d2 = paramOptions.outHeight;
    int i;
    int j;
    if (paramInt2 == -1)
    {
      i = 1;
      if (paramInt1 != -1)
        break label60;
      j = 128;
      label31: if (j >= i)
        break label84;
    }
    label60: label84: 
    do
    {
      return i;
      i = (int)Math.ceil(Math.sqrt(d1 * d2 / paramInt2));
      break;
      j = (int)Math.min(Math.floor(d1 / paramInt1), Math.floor(d2 / paramInt1));
      break label31;
      if ((paramInt2 == -1) && (paramInt1 == -1))
        return 1;
    }
    while (paramInt1 == -1);
    return j;
  }

  public static int computeSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
  {
    int i = computeInitialSampleSize(paramOptions, paramInt1, paramInt2);
    if (i <= 8)
    {
      int j = 1;
      while (true)
      {
        if (j >= i)
          return j;
        j <<= 1;
      }
    }
    return 8 * ((i + 7) / 8);
  }

  public static Drawable decodeFile(String paramString)
  {
    try
    {
      BitmapFactory.Options localOptions1 = new BitmapFactory.Options();
      localOptions1.inJustDecodeBounds = true;
      File localFile = new File(paramString);
      BitmapFactory.decodeStream(new FileInputStream(localFile), null, localOptions1);
      int i = 1;
      while (true)
      {
        if ((localOptions1.outWidth / i / 2 < 400) || (localOptions1.outHeight / i / 2 < 400))
        {
          BitmapFactory.Options localOptions2 = new BitmapFactory.Options();
          localOptions2.inSampleSize = i;
          BitmapDrawable localBitmapDrawable = new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(localFile), null, localOptions2));
          return localBitmapDrawable;
        }
        i *= 2;
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
    }
    return null;
  }

  public static Bitmap getBitmapFromFile(String paramString, int paramInt1, int paramInt2)
  {
    File localFile = new File(paramString);
    if ((localFile != null) && (localFile.exists()))
    {
      BitmapFactory.Options localOptions = null;
      if (paramInt1 > 0)
      {
        localOptions = null;
        if (paramInt2 > 0)
        {
          localOptions = new BitmapFactory.Options();
          localOptions.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(localFile.getPath(), localOptions);
          localOptions.inSampleSize = computeSampleSize(localOptions, Math.min(paramInt1, paramInt2), paramInt1 * paramInt2);
          localOptions.inJustDecodeBounds = false;
          localOptions.inInputShareable = true;
          localOptions.inPurgeable = true;
        }
      }
      try
      {
        Bitmap localBitmap = BitmapFactory.decodeFile(localFile.getPath(), localOptions);
        return localBitmap;
      }
      catch (OutOfMemoryError localOutOfMemoryError)
      {
        localOutOfMemoryError.printStackTrace();
      }
    }
    return null;
  }

  public static Drawable getDrawable(Context paramContext, String paramString, Boolean paramBoolean)
  {
    Drawable localDrawable;
    try
    {
      if (paramBoolean.booleanValue());
      for (String str1 = Global.IMGPATH; ; str1 = Global.IMGPATHMEMORY)
      {
        int i = paramString.length();
        localDrawable = null;
        if (i <= 0)
          break;
        String str2 = str1 + paramString.substring(1 + paramString.lastIndexOf("/"), paramString.lastIndexOf("."));
        File localFile = new File(str2);
        boolean bool1 = localFile.exists();
        localDrawable = null;
        if (!bool1)
          break;
        boolean bool2 = localFile.length() < 0L;
        localDrawable = null;
        if (!bool2)
          break;
        localDrawable = decodeFile(str2);
        break;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return null;
    }
    return localDrawable;
  }

  public static Bitmap getImageForOutOfApp(String paramString)
  {
    new BitmapFactory.Options().inSampleSize = 4;
    return BitmapFactory.decodeFile(paramString);
  }

  public static Bitmap getInnerWallpaper(Context paramContext, String paramString)
  {
    try
    {
      Bitmap localBitmap = BitmapFactory.decodeStream(paramContext.getAssets().open(paramString, 3));
      return localBitmap;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  public static Bitmap getInnerWallpaper2(Context paramContext, String paramString)
  {
    new BitmapFactory.Options().inSampleSize = 4;
    try
    {
      Bitmap localBitmap = BitmapFactory.decodeStream(paramContext.getAssets().open(paramString, 3));
      return localBitmap;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  public static void loadLogoImage(final Context paramContext, ImageView paramImageView, String paramString, Boolean paramBoolean)
  {
    try
    {
      String str1;
      if (paramBoolean.booleanValue())
        str1 = Global.IMGPATH;
      while (paramString.length() > 0)
      {
        String str2 = str1 + paramString.substring(1 + paramString.lastIndexOf("/"), paramString.lastIndexOf("."));
        File localFile = new File(str2);
        if ((localFile.exists()) && (localFile.length() != 0L))
        {
          paramImageView.setImageBitmap(BitmapFactory.decodeFile(str2));
          return;
          str1 = Global.IMGPATHMEMORY;
        }
        else
        {
          if ((localFile.exists()) && (localFile.length() == 0L))
            localFile.delete();
          ImageDownloadTask localImageDownloadTask = new ImageDownloadTask();
          Object[] arrayOfObject = new Object[2];
          arrayOfObject[0] = paramString;
          arrayOfObject[1] = new Handler()
          {
            public void handleMessage(Message paramAnonymousMessage)
            {
              if (paramAnonymousMessage.obj != null)
              {
                String str = (String)paramAnonymousMessage.obj;
                ImageHelper.this.setImageBitmap(BitmapFactory.decodeFile(str));
                return;
              }
              ImageHelper.this.setImageDrawable(paramContext.getResources().getDrawable(2130838074));
            }
          };
          localImageDownloadTask.execute(arrayOfObject);
          return;
        }
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    paramImageView.setImageDrawable(paramContext.getResources().getDrawable(2130838074));
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.component.ImageHelper
 * JD-Core Version:    0.6.2
 */